package com.ubb.dbms.core.operatorEvaluator.util;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import com.ubb.dbms.domain.queryResult.SelectResult;
import com.ubb.dbms.domain.queryResult.SelectedRow;

public final class JsonConverter {

	private JsonConverter() {
		//utility class
	}
	
	public static JSONObject getJsonFromSelectResult(SelectResult selectResult) {
		JSONObject jsObject = new JSONObject();
		jsObject.put("resultsLength", selectResult.getSelectedRows().size());
		JSONArray array = new JSONArray();
		for (SelectedRow row:selectResult.getSelectedRows()) {
			JSONObject jsonObject = new JSONObject();
			jsonObject.putAll(row.getRowValues());
			array.add(jsonObject);
		}
		jsObject.put("result", array);
		return jsObject;
	}
	
//	public static JSONObject getJsonFromSelectResult2(SelectResult selectResult) {
//		JSONObject jsonObject = new JSONObject();
//		jsonObject.put("selectResult", JSONObject.fromObject(selectResult));
//		return jsonObject;
//	}
}
